package com.bp.hearthealth.pulse.lnapps.bp_network

import android.content.Context
import android.net.ConnectivityManager

/**
 * @author isnoam
 * @package_name CheckNetwork
 * @description：
 */
class BpCheckNetwork {

    companion object{
        /**
         * 判断网络是否连通
         */
        fun isNetworkConnected(context: Context?): Boolean {
            return try {
                if (context != null) {
                    val cm = context
                        .getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
                    val info = cm.activeNetworkInfo
                    info != null && info.isConnected
                } else {
                    /**如果context为空，就返回false，表示网络未连接 */
                    false
                }
            } catch (e: Exception) {
                e.printStackTrace()
                false
            }
        }

        fun isWifiConnected(context: Context?): Boolean {
            return if (context != null) {
                val cm = context
                    .getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
                val info = cm.activeNetworkInfo
                info != null && info.type == ConnectivityManager.TYPE_WIFI
            } else {
                /**如果context为null就表示为未连接 */
                false
            }
        }
    }


}